package com.chaowen.yixin;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chaowen.config.Config;
import com.chaowen.model.UserInfo;

public class LeftSlidingMenuFragment extends Fragment implements OnClickListener{
	private View yixinBtnLayout;
	private View circleBtnLayout;
	private View settingBtnLayout;
	private Handler handler;
//	private TextView ivTitleName;
	
	public LeftSlidingMenuFragment(Handler handler) {
		this.handler = handler;
	}
	
     @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	
    }
     
     @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
    		Bundle savedInstanceState) {
    	 View view = inflater.inflate(R.layout.main_left_fragment, container,
 				false);
    	  yixinBtnLayout = view.findViewById(R.id.yixinBtnLayout);
    	  yixinBtnLayout.setOnClickListener(this);
    	  circleBtnLayout = view.findViewById(R.id.circleBtnLayout);
    	  circleBtnLayout.setOnClickListener(this);
    	  settingBtnLayout = view.findViewById(R.id.settingBtnLayout);
    	  settingBtnLayout.setOnClickListener(this);
    	  //设置默认选中位置
    	  yixinBtnLayout.setSelected(true);
    	  TextView nickNameTextView =(TextView)view.findViewById(R.id.nickNameTextView);
    	  nickNameTextView.setText(UserInfo.userName);
    	return view;
    }

	@Override
	public void onClick(View v) {
		Fragment newContent = null;
		switch (v.getId()) {
		case R.id.yixinBtnLayout:
			newContent = new Fragment_login(handler);
			yixinBtnLayout.setSelected(true);
			circleBtnLayout.setSelected(false);
			settingBtnLayout.setSelected(false);
			Config.titleName = "登陆";
			break;
		case R.id.circleBtnLayout:
			newContent = new Fragment_sign(handler);
			yixinBtnLayout.setSelected(false);
			circleBtnLayout.setSelected(true);
			settingBtnLayout.setSelected(false);
			Config.titleName = "签到";
			break;
		case R.id.settingBtnLayout:
			newContent = new Fragment_answer(handler);
			yixinBtnLayout.setSelected(false);
			circleBtnLayout.setSelected(false);
			settingBtnLayout.setSelected(true);
			Config.titleName = "答题";
		    break;
		default:
			break;
		}
		if (newContent != null)
			switchFragment(newContent);
	}
	
	/**
	 * 切换界面
	 * @param fragment
	 */
	private void switchFragment(Fragment fragment) {
		if (getActivity() == null)
			return;
			MainActivity ra = (MainActivity) getActivity();
			ra.switchContent(fragment);
	}
}
